// app.js
App({
  onLaunch() {
    // 登录
    let invitedUser =
      wx.getStorageSync('invitedUser') || ''

    wx.login({
      success: (res) => {
        // return
        wx.request({
          url:
            'https://elf.byxfd.com/mini/api/mine/login',
          method: 'POST',
          data: {
            code: res.code,
            map: {
              invitedUser: invitedUser
            }
          },
          success: (res) => {
            wx.removeStorageSync('invitedUser')
            if (
              res.statusCode == 200 &&
              res.data.code == 200
            ) {
              this.globalData.token =
                res.data.data.token
              this.globalData.userInfo =
                res.data.data.user.extParam
              wx.setStorageSync(
                'token',
                res.data.data.token
              )
              this.globalData.isLogin = true
            } else {
              this.globalData.token = ''
              this.globalData.userInfo = {}
              this.globalData.isLogin = false
            }
          },
          fail: (err) => {
            console.log(err)
          }
        })
      }
    })
  },
  getCurrentTabbar(selected, that) {
    if (
      typeof that.getTabBar === 'function' &&
      that.getTabBar()
    ) {
      that.getTabBar().setData({
        selected: selected
      })
    }
  },
  globalData: {
    userInfo: null,
    token: '',
    isLogin: false,
    showModel: false,
    imgSrc: ''
  }
})
